<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>关键词管理-[[${T(com.b2c.erp.DataConfigObject).getInstance().getSysName()}]]</title>

</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this">关键词列表&nbsp;&nbsp;<span th:text="${parentName}"></span></li>
            <li th:if="${parentId != null}"><a href="javascript:history.back();">返回上一页</a></li>
        </ul>
    </div>
    <style>
        .hideAddress{
            width: 300px;
            display: inline-block;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <style>
        .sp-tree {
            display: none;
            position: absolute;
            z-index: 199999999;
            width: 300px;
            /*height: 100px;*/
            padding: 10px;
            overflow-y: auto;
            background: #fff;
            border: 1px solid #d3d3d3;
        }

        .sp-tree li {
            position: relative;
            font-size: 12px;
            line-height: 20px;
            padding-left: 20px
        }

        .sp-tree li li {
            border-left: 1px solid #ccc;
        }

        .sp-tree li h3 {
            font-weight: normal;
            cursor: pointer;
        }

        .sp-tree li h3 b {
        }

        .sp-tree li h3 b:hover {
            text-decoration: underline;
        }

        .sp-tree li i {
            position: absolute;
            left: 0;
            top: 0;
            font-size: 16px;
            font-weight: bold;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
        }

        .sp-tree li ul {
            display: none;
        }
    </style>
    <!-- content starts -->
    <!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" th:action="@{/big_data/keyword_list}">

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="keyword" th:value="${keyword}" placeholder="关键词" class="layui-input" autocomplete="off" style="width: 200px">
                    </div>
                    <div class="layui-inline" id="categoryDIV">
                        <input type="text" name="category" id="sp-sort" th:value="${category}" placeholder="类目" class="layui-input" autocomplete="off" style="width: 200px">
                        <input type="hidden" name="categoryId" id="categoryId" th:value="${categoryId}"/>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="source" id="source">
                                <option value="">平台</option>
                                <option value="TAOBAO">淘宝</option>
                                <option value="PDD">拼多多</option>
                                <option value="QITA">其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">年份</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="year" id="startTime" th:value="${year}" autocomplete="off"
                                   placeholder="yyyy">
                        </div>

                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                    <div class="layui-inline">
                        <a href="javascript:;" id="add_keyword" class="layui-btn layui-btn-normal">添加新关键词</a>
                    </div>
                    <div class="layui-inline">
                        <a href="/big_data/keyword_import" class="layui-btn layui-btn-warm">导入关键词</a>
                    </div>
                </div>

            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
               <th>序号</th>

                <th>关键词</th>
                <th>类目</th>
                <th>平台</th>
                <th>搜索人气</th>
                <th>搜索热度</th>
                <th >点击人气</th>
                <th >点击热度</th>
                <th >点击率</th>
                <th>支付转化率</th>
                <th>收录日期</th>
                <th>创建时间</th>
                <th></th>
            </tr>
            <tr th:each="item:${lists}">
               <td th:text="${itemStat.index +1}"></td>

                <td>
                    <p th:text="${item.keyword}"></p>
                </td>
                <td><p th:text="${item.categoryName}"></p></td>
                <td><p th:text="${item.source}"></p></td>
                <td >
                    <p th:text="${item.sousuorenqi}"></p>
                </td>
                <td th:text="${item.sousuoredu}"></td>
                <td th:text="${item.dianjirenqi}"></td>
                <td th:text="${item.dianjiredu}"></td>
                <td >
                    <span th:text="${item.dianjilv *100}"></span>%
                </td>
                <td th:text="${item.zhifulv}"></td>
                <td th:text="${item.includeDate}"></td>
                <td th:text="${item.createTime}"></td>
                <td>
                    <a th:href="@{/big_data/keyword_list(parentId=${item.id})}" th:if="${item.depth < 3}">查看更多</a>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>


    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;


        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
                ,type:'year'
            });

            $("#source").val('[[${source}]]');
            form.render();
            var category = '[[${category}]]';
            var categoryId = '[[${categoryId}]]';
            $("#sp-sort").val(category);
            $("#categoryId").val(categoryId);

            $(function () {
                $("#add_keyword").click(function(){
                    layer.open({
                        type: 2,
                        title: '添加新关键词',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['600px', '65%'],
                        content: '/big_data/keyword_add'
                    });
                })
            })
        });

//商品分类
$(function () {
            var $sort = null;
            var $tree = null;
            var $status = false;
            var $data = null;
            var $cateId = 0;

            function create(data) {
                if (!data || data.length < 1) return;
                for (var i = 0, n = data.length, tpl = ''; i < n; i++) {
                    if (data[i].child && data[i].child.length > 0) {
                        tpl += '<li><h3><i>+</i><span style="background:#918597" data-id=' + data[i].id + '>' +data[i].id+ data[i].name + '</span></h3><ul style="display: block;">' + create(data[i].child) + '</ul></li>';
                    } else {
                        tpl += '<li><h3><b data-id=' + data[i].id + '>' + data[i].name + '</b></h3></li>';
                    }
                }
                return tpl;
            }


            //商品分类初始化
            function init() {
                $tree = $('<ul class="sp-tree"></ul>').appendTo($('#categoryDIV'));

                $(document).click(function (e) {
                    if ($status) {
                        $tree.hide();
                        $status = false;
                    }
                });
                $tree.delegate('i', 'click', function (e) {
                    e.stopPropagation();
                    var _this = $(this);
                    var _h = _this.parent('h3');
                    var _box = _h.next('ul');
                    if (_box.css('display') === 'none') {
                        _box.show();
                        _this.html('-');
                    } else {
                        _box.hide();
                        _this.html('+');
                    }
                });
                $tree.delegate('b', 'click', function (e) {
                    e.stopPropagation();
                    $sort.val($(this).text());
                    $("#categoryId").val($(this).attr('data-id'));
                    $tree.hide();
                    $status = false;
                    $cateId = $(this).attr('data-id');
                    console.log($(this).attr('data-id') + " + " + $cateId);
                });
                $tree.click(function (e) {
                    e.stopPropagation();
                });
            }

            function render() {
                $tree.html(create($data));
                $sort = $('#sp-sort');
                $sort.click(function (e) {
                    e.stopPropagation();
                    var _this = $(this);
                    var pos = _this.offset();
                    var x = 0;//pos.left - 280;
                    var y = 40;//pos.top + _this.outerHeight() - 60;
                    $tree.css({
                        left: x,
                        top: y
                    }).show();
                    $status = true;
                });
            }

            // ajax 获得分类数据 完成后执行 init()
            $.ajax({
                url: '/ajax_goods/json_category',
                type: "POST",
                dataType: 'json',
                contentType: 'application/json',
                success: function (res) {
                    // $data = res.msg;
                    // $data.replace(/&quot;/g,'\"');
                    $data = eval('(' + res.msg + ')');
                    console.log($data);

                    init();
                    render();
                }
            });
        })
    </script>


</div>
</body>
</html>
